package com.heima.comment.controller;

import com.heima.apis.comment.ComentControllerApi;
import com.heima.comment.service.ComentService;
import com.heima.model.comment.dtos.CommentDto;
import com.heima.model.comment.dtos.CommentLikeDto;
import com.heima.model.comment.dtos.CommentSaveDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/comment")
public class ComentController implements ComentControllerApi {


    @Autowired
    ComentService comentService;

    /**
     * 添加评论
     * @param dto
     * @return
     */
    @PostMapping("/add")
    @Override
    public ResponseResult addComment(@RequestBody CommentSaveDto dto) {
        return comentService.add(dto);
    }

    /**
     * 给评论点赞
     * @param dto
     * @return
     */
    @PostMapping("/like")
    @Override
    public ResponseResult like(@RequestBody CommentLikeDto dto) {

        return comentService.like(dto);
    }

    /**
     * 根据文章id，获取文章评论
     * @param dto
     * @return
     */
    @PostMapping("/like")
    @Override
    public ResponseResult findByArticleId(@RequestBody CommentDto dto) {

        return comentService.findByArticleId(dto);
    }
}
